 package uk.co.mmscomputing.device.twain;
 
 import java.io.PrintStream;
 import java.util.Vector;
 
 public class TwainIdentity
   implements TwainConstants
 {
   private TwainSourceManager manager;
   protected byte[] identity;
 
   TwainIdentity(TwainSourceManager paramTwainSourceManager)
   {
     this.manager = paramTwainSourceManager;
     this.identity = new byte[''];
   }
 
   TwainIdentity(TwainSourceManager paramTwainSourceManager, byte[] paramArrayOfByte) {
     this.manager = paramTwainSourceManager;
     this.identity = paramArrayOfByte;
   }
 
   boolean isTwain20Source() {
     int i = jtwain.getINT32(this.identity, 50);
     return (i & 0x40000000) == 1073741824;
   }
 
   void maskTwain20Source() {
     int i = jtwain.getINT32(this.identity, 50);
     jtwain.setINT32(this.identity, 50, i & 0xBFFFFFFF);
   }
 
   void getDefault()
   {
     try
     {
       this.manager.call(1, 3, 3, this.identity);
     }
     catch (TwainIOException localTwainIOException) {
     }
   }
 
   void userSelect() throws TwainIOException {
     this.manager.call(1, 3, 1027, this.identity);
   }
 
   void open() throws TwainIOException {
     this.manager.call(1, 3, 1025, this.identity);
   }
 
   void getFirst() throws TwainIOException {
     this.manager.call(1, 3, 4, this.identity);
   }
 
   void getNext() throws TwainIOException {
     this.manager.call(1, 3, 5, this.identity);
   }
   public int getId() {
     return jtwain.getINT32(this.identity, 0); } 
   public int getMajorNum() { return jtwain.getINT16(this.identity, 4); } 
   public int getMinorNum() { return jtwain.getINT16(this.identity, 6); } 
   public int getLanguage() { return jtwain.getINT16(this.identity, 8); } 
   public int getCountry() { return jtwain.getINT16(this.identity, 10); }
 
   public String getInfo() {
     String str = "";
     for (int i = 12; (this.identity[i] != 0) && (i < 46); i++) {
       str = str + (char)this.identity[i];
     }
     return str;
   }
   public int getProtocolMajor() {
     return jtwain.getINT16(this.identity, 46); } 
   public int getProtocolMinor() { return jtwain.getINT16(this.identity, 48); } 
   public int getSupportedGroups() { return jtwain.getINT32(this.identity, 50); }
 
   public String getManufacturer() {
     String str = "";
     for (int i = 54; (this.identity[i] != 0) && (i < 88); i++) {
       str = str + (char)this.identity[i];
     }
     return str;
   }
 
   public String getProductFamily() {
     String str = "";
     for (int i = 88; (this.identity[i] != 0) && (i < 122); i++) {
       str = str + (char)this.identity[i];
     }
     return str;
   }
 
   public String getProductName() {
     String str = "";
     for (int i = 122; (this.identity[i] != 0) && (i < 156); i++) {
       str = str + (char)this.identity[i];
     }
     return str;
   }
 
   public String toString() {
     String str = "TwainIdentity\n";
     str = str + "\tid               = 0x" + Integer.toHexString(getId()) + "\n";
     str = str + "\tmajorNum         = 0x" + Integer.toHexString(getMajorNum()) + "\n";
     str = str + "\tminorNum         = 0x" + Integer.toHexString(getMinorNum()) + "\n";
     str = str + "\tlanguage         = 0x" + Integer.toHexString(getLanguage()) + "\n";
     str = str + "\tcountry          = 0x" + Integer.toHexString(getCountry()) + "\n";
     str = str + "\tinfo             = " + getInfo() + "\n";
     str = str + "\tprotocol major   = 0x" + Integer.toHexString(getProtocolMajor()) + "\n";
     str = str + "\tprotocol minor   = 0x" + Integer.toHexString(getProtocolMinor()) + "\n";
     str = str + "\tsupported groups = 0x" + Integer.toHexString(getSupportedGroups()) + "\n";
     str = str + "\tmanufacturer     = " + getManufacturer() + "\n";
     str = str + "\tproduct family   = " + getProductFamily() + "\n";
     str = str + "\tproduct name     = " + getProductName() + "\n";
 
     str = str + "\ttwain 2.0 source = " + isTwain20Source() + "\n";
     return str;
   }
 
   public static TwainIdentity[] getIdentities() throws TwainIOException {
     TwainSourceManager localTwainSourceManager = jtwain.getSourceManager();
     Vector localVector = new Vector();
     try {
       TwainIdentity localTwainIdentity = new TwainIdentity(localTwainSourceManager);
       localTwainIdentity.getFirst();
       localVector.add(localTwainIdentity);
       while (true) {
         localTwainIdentity = new TwainIdentity(localTwainSourceManager);
         localTwainIdentity.getNext();
         localVector.add(localTwainIdentity);
       }
     } catch (TwainResultException.EndOfList localEndOfList) {
     } catch (TwainIOException localTwainIOException) {
       System.out.println("uk.co.mmscomputing.device.twain.TwainIdentity.getIdentities:\n\t" + localTwainIOException);
     }
     return (TwainIdentity[])localVector.toArray(new TwainIdentity[0]);
   }
 
   public static String[] getProductNames() throws TwainIOException {
     TwainSourceManager localTwainSourceManager = jtwain.getSourceManager();
     Vector localVector = new Vector();
     try {
       TwainIdentity localTwainIdentity = new TwainIdentity(localTwainSourceManager);
       localTwainIdentity.getFirst();
       localVector.add(localTwainIdentity.getProductName());
       while (true) {
         localTwainIdentity = new TwainIdentity(localTwainSourceManager);
         localTwainIdentity.getNext();
         localVector.add(localTwainIdentity.getProductName());
       }
     } catch (TwainResultException.EndOfList localEndOfList) {
     } catch (TwainIOException localTwainIOException) {
       System.out.println("uk.co.mmscomputing.device.twain.TwainIdentity.getProductNames:\n\t" + localTwainIOException);
     }
     return (String[])localVector.toArray(new String[0]);
   }
 }

